using System;
using NUnit.Framework;
using SmartClientPlatform.RemoteClientBase;

namespace SmartClientPlatform.OMS.Test
{
    [TestFixture]
    public class Tester 
    {
        [Test]
        public void Test1()
        {
            RemotingHelper.Execute(
                service1 =>
                {
                        foreach (var order in service1.GetOrders())
                    {
                        Console.WriteLine("{0}, {1}, {2} {3}",
                                          order.OrderID,
                                          order.OrderDate,
                                          order.Customer.FirstName,
                                          order.Customer.LastName);
                        foreach (var orderDetail in order.OrderDetails)
                        {
                            Console.WriteLine("\t{0}, {1}, {2}",
                                              orderDetail.Product.Name,
                                              orderDetail.Price,
                                              orderDetail.Quantity);
                        }
                    }

                });
        }

        [Test]
        public void Test2()
        {
            var changesTracker = new ChangesTracker();

            var orderDtos = RemotingHelper.Execute(
                service1 => changesTracker.Invoke(() => service1.GetOrders()));

            orderDtos[0].OrderDate = DateTime.Now;

            RemotingHelper.Execute(
                service1 => service1.SaveOrders(changesTracker.GetDataChanges()));
        }

    }
}